using System;

namespace RedDotSystem
{
    public class RedDotTreeNode
    {
        /// <summary>
        /// 红点类型
        /// </summary>
        public RedDotType redDotType;
        /// <summary>
        /// 父节点
        /// </summary>
        public RedDotDefine parentNode;
        /// <summary>
        /// 当前节点
        /// </summary>
        public RedDotDefine node;
        /// <summary>
        /// 红点显示状态
        /// </summary>
        public bool redDotActive;
        /// <summary>
        /// 红点显示个数
        /// </summary>
        public int redDotCount;

        /// <summary>
        /// 状态改变事件
        /// </summary>
        public Action<RedDotType, bool, int> OnRedDotActiveChange;

        /// <summary>
        /// 红点逻辑处理
        /// </summary>
        public Action<RedDotTreeNode> logicHander;

        /// <summary>
        /// 刷新红点状态
        /// </summary>
        /// <returns></returns>
        public virtual bool RefreshRedDotState()
        {
            redDotCount = 0;
            if (redDotType == RedDotType.RedDotNodeNum)
            {
                //TODO:获取子节点显示的红点个数
                redDotCount = RedDotSystem.Instance.GetChildNodeRedDotCount(node);
                redDotActive = redDotCount > 0;
            }
            else
            {
                redDotCount = RefreshRedDotCont();
            }

            logicHander?.Invoke(this);

            if (redDotType == RedDotType.RedDotDataNum)
            {
                redDotActive = redDotCount > 0;
            }

            OnRedDotActiveChange?.Invoke(redDotType, redDotActive, redDotCount);

            return redDotActive;
        }

        /// <summary>
        /// 刷新红点数量
        /// </summary>
        /// <returns></returns>
        public virtual int RefreshRedDotCont()
        {
            return 1;
        }
    }
}

